package org.linuxgears.BouncingBall;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by IntelliJ IDEA.
 * User: grim
 * Date: 7 ��� 2010
 * Time: 23:16:38
 * To change this template use File | Settings | File Templates.
 */
public class BallToolButton extends JButton implements ActionListener {
    protected Ball prototype;
    protected BallController controller;

    public BallToolButton(Ball prototype, BallController controller) {
        this.prototype = prototype;
        this.controller = controller;
        this.setIcon(new BallIcon(BallPainterFactory.getInstance().createBallPainter(prototype, null)));
        this.setPreferredSize(new Dimension(this.getIcon().getIconWidth(), this.getIcon().getIconHeight()));
        this.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
    	// TODO: implement this using Flyweight pattern
        controller.addBall(prototype.clone());
    }
}